// 运行时配置

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://umijs.org/docs/api/runtime-config#getinitialstate
import type { RequestConfig } from 'umi';
import { message } from 'antd';
export async function getInitialState(): Promise<{ name: string }> {
  return { name: '@umijs/max' };
}

export const layout = () => {
  return {
    logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
    menu: {
      locale: false,
    },
  };
};

export const request: RequestConfig = {
  timeout: 3000,
  // other axios options you want
  errorConfig: {
    errorHandler() {
    },
    errorThrower() {
    }
  },
  requestInterceptors: [(url, options) => {
    options.headers['x-csrf-token'] = document.cookie && document.cookie.split('=')[1];
    // do something
    return { url, options }
  }],
  responseInterceptors: [(response) => {
    const { data } = response;
    const whiteList = [
      '/api/v1/queryUserList',
    ];
    let flag = whiteList.some(item => item === response.config.url);
    if (!flag && data && data.code !== 1) {
      message.error(data.msg);
      return Promise.reject(data);
    }
    return response;
  }]
};
